﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

namespace Cemit.NetFramework.Demo.Tutorial2
{
    /// <summary>
    /// 本教程会使用设置文件连接服务器，并在Text打印服务器的IP和端口
    /// </summary>
    public sealed class NetworkManager : MonoBehaviour
    {
        //你可以通过顶栏菜单[PolyNetwork-Create Server Settings]创建默认配置
        //或者通过在Project窗口内的[右键-Create-PolyNetwork-ServerSettings]创建默认配置
        //然后将配置拖到本游戏对象的Inspector窗口为settings字段赋值
        public PolyServerSettings settings;
        public Text text;

        void Start()
        {
            //设置监听
            PolyNetwork.OnConnectionSucceeded += 
                () => text.text = $"{settings.ip}:{settings.port}";

            //使用配置文件连接至服务器
            PolyNetwork.Connect(settings);
        }
    }
}